#include "config.h"
#include <QSettings>

Config::Config()
{

}

Config::~Config()
{

}

void Config::getConfigs()
{
    // 读取参数
    QSettings Config("RemoteDesktopConfig", QSettings::IniFormat);
    QString ConfigPPI = Config.value("PPI").toString();
    QString ConfigBit = Config.value("BIT").toString();
    QString ConfigFPS = Config.value("FPS").toString();
    // 存入类变量
    if(ConfigPPI == "800_600")
    {
        scWidth = 800;
        scHeight = 600;
        indexX = 8;
        indexY = 6;
    }else if(ConfigPPI == "1024_768")
    {
        scWidth = 1024;
        scHeight = 768;
        indexX = 8;
        indexY = 6;
    }else if(ConfigPPI == "1280_800")
    {
        scWidth = 1280;
        scHeight = 800;
        indexX = 10;
        indexY = 10;
    }else if(ConfigPPI == "1440_900")
    {
        scWidth = 1440;
        scHeight = 900;
        indexX = 12;
        indexY = 10;
    }else
    {
        scWidth = 0;
        scHeight = 0;
        indexX = 0;
        indexY = 0;
    }
    if(ConfigBit == "8bit")
    {
        bit =8;
    }else if(ConfigBit == "16bit")
    {
        bit = 16;
    }else if(ConfigBit == "24bit")
    {
        bit = 24;
    }else if(ConfigBit == "32bit")
    {
        bit = 32;
    }else
    {
        bit = 0;
    }
    if(ConfigFPS == "10ms")
    {
        fps = 10;
    }else if(ConfigFPS == "50ms")
    {
        fps = 50;
    }else if(ConfigFPS == "100ms")
    {
        fps = 100;
    }else if(ConfigFPS == "500ms")
    {
        fps = 500;
    }else
    {
        fps = 0;
    }
    serverPort = Config.value("SERVERPORT", 0).toInt();
}

void Config::setConfigs()
{
    // PPI
    QSettings Config("RemoteDesktopConfig", QSettings::IniFormat);
    if(scWidth == 800 && scHeight == 600)
    {
        Config.setValue("PPI", QVariant("800_600"));
    }
    else if(scWidth == 1024 && scHeight == 768)
    {
        Config.setValue("PPI", QVariant("1024_768"));
    }
    else if(scWidth == 1280 && scHeight == 800)
    {
        Config.setValue("PPI", QVariant("1280_800"));
    }
    else if(scWidth == 1440 && scHeight == 900)
    {
        Config.setValue("PPI", QVariant("1440_900"));
    }else
    {

    }

    // bit
    switch(bit)
    {
    case 8:
        Config.setValue("BIT", QVariant("8bit"));
        break;
    case 16:
        Config.setValue("BIT", QVariant("16bit"));
        break;
    case 24:
        Config.setValue("BIT", QVariant("24bit"));
        break;
    case 32:
        Config.setValue("BIT", QVariant("32bit"));
        break;
    }

    switch (fps) {
    case 10:
        Config.setValue("FPS", QVariant("10ms"));
        break;
    case 50:
        Config.setValue("FPS", QVariant("50ms"));
        break;
    case 100:
        Config.setValue("FPS", QVariant("100ms"));
        break;
    case 500:
        Config.setValue("FPS", QVariant("500ms"));
        break;
    }

    Config.setValue("SERVERPORT", QVariant(serverPort));
}
